﻿using System;
using System.Runtime.Serialization;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;

namespace Faust.Andrew.MTG.Player.Shared
{
    /// <summary>
    /// Information needed to represent a cardID's location on the game board
    /// </summary>
    [DataContract]
    public class Location : INotifyPropertyChanged
    {
        public Location() { }

        public Location(int playerId, Zone zone)
        {
            Zone = zone;
            PlayerID = playerId;
        }

        private Zone _zone;
        /// <summary>
        /// Which zone the cardID is in
        /// </summary>
        /// <remarks>
        /// If Zone is Attached then no other zone information will be will be provided. The cardID it's attached to will handle the details of the placement and location.
        /// If Zone is Attacking, then targetPlayerID it the player being attacked
        /// </remarks>
        [DataMember]
        public Zone Zone
        {
            get
            {
                return _zone;
            }
            set
            {
                if (_zone != value)
                {
                    _zone = value;
                    FirePropertyChanged("Zone");
                }
            }
        }

        private int _playerID;
        /// <summary>
        /// Which targetPlayerID's play area the cardID is in
        /// </summary>
        [DataMember]
        public int PlayerID
        {
            get
            {
                return _playerID;
            }
            set
            {
                if (_playerID != value)
                {
                    _playerID = value;
                    FirePropertyChanged("PlayerID");
                }
            }
        }

        private int _order;
        /// <summary>
        /// The order that cardID is in within the given Zone.
        /// </summary>
        /// <remarks>
        /// For the Deck zone, this will be the position in the deck the cardID is at with 0 being the bottom of the deck.
        /// For all other zones the UI can choose what the order means to it.
        /// </remarks>
        [DataMember]
        public int Order
        {
            get
            {
                return _order;
            }
            set
            {
                if (_order != value)
                {
                    _order = value;
                    FirePropertyChanged("Order");
                }
            }
        }

        private double _x;
        [DataMember]
        public double X
        {
            get
            {
                return _x;
            }
            set
            {
                if (_x != value)
                {
                    _x = value;
                    FirePropertyChanged("X");
                }
            }
        }
        private double _y;
        [DataMember]
        public double Y
        {
            get
            {
                return _y;
            }
            set
            {
                if (_y != value)
                {
                    _y = value;
                    FirePropertyChanged("Y");
                }
            }
        }

        private double _z;
        /// <summary>
        /// Specifies the order in which the cards are stacked.
        /// </summary>
        [DataMember]
        public double Z
        {
            get
            {
                return _z;
            }
            set
            {
                if (_z != value)
                {
                    _z = value;
                    FirePropertyChanged("Z");
                }
            }
        }


        #region INotifyPropertyChanged Members

        public event PropertyChangedEventHandler PropertyChanged;

        protected void FirePropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }
        #endregion
    }
}
